package com.example.demo;


import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("list")
public class MassageController {

     List<Message> messages = new ArrayList<>();
    @RequestMapping("getlist")
    public List<Message> getList(){

        return messages;
    }

    @RequestMapping(value = "publish", produces = "application/json")
    public String publish(@RequestBody Message message){
        if(StringUtils.hasLength(message.getFrom())
                && StringUtils.hasLength(message.getTo())
                && StringUtils.hasLength(message.getSay())){
            messages.add(message);
            return "{\"ok\": 1}";
        }
        return "{\"ok\": 0}";
    }
}
